<template>

	<view class="padding" :style="'height:'+screenHeight+'px;'">
		<view class="boxconten" style="height: 100%;">
			<view class="one">
			</view>
			<view class="two">
				<view style="twoicon"><u-icon name="clock" color="#878787" size="40" :label="'姓名： '+item.name"></u-icon>
				</view>
				<view style="twoicon"><u-icon name="account" color="#a1a1a1" size="40"
						:label="'证件号码： '+item.idNumber"></u-icon></view>
				<view style="twoicon"><u-icon name="account" color="#a1a1a1" size="40"
						:label="'性别： '+item.gender"></u-icon></view>
				<view style="twoicon"><u-icon name="account" color="#a1a1a1" size="40"
						:label="'出生日期： '+item.birthday"></u-icon></view>
				<view style="twoicon"><u-icon name="chat" color="#a1a1a1" size="40"
						:label="'电话号码： '+item.phone1"></u-icon></view>
				<view style="twoicon"><u-icon name="chat" color="#a1a1a1" size="40"
						:label="'民族： '+item.nation"></u-icon></view>
				<view style="twoicon"><u-icon name="chat" color="#a1a1a1" size="40"
						:label="'住址： '+item.address"></u-icon></view>
			</view>


			<view class="" >
				<view class="bottom-button">
					<view class="bottom-button">
						<!-- <u-button shape="circle" type="primary" size="default" @click="submit">提交</u-button> -->
						<view class="button" @click="addvisit()">
							<span>提交</span>
						</view>
					</view>
				</view>

			</view>

			
		<!-- 	<view class="" @click="getmoren()">
				获取默认就诊人
			</view> -->
			<!-- <view class="" @click="shanchu()">
				添加默认就诊人
			</view> -->
		</view>
		
		
		
	</view>
</template>

<script>
	import axios from 'axios'
	import UQRCode from 'uqrcodejs';
	import {
		mapState,
		mapGetters
	} from 'vuex'
	export default {
		data() {
			return {
				moren:'',
				healthCode: '',
				screenHeight: getApp().globalData.screenHeight - 44,
				OrderId: '',
				showPay: false,
				refund: false,
				cancellationtext: '取消预约后将无法撤回，是否取消',
				cancellationComfirm: "取消成功",
				cancellationshow: false,
				cancellationComfirmshow: false,
				deletetext: '删除记录后无法找回，是否删除',
				deleteshow: false,
				content2: '请确认支付！',
				content3: '是否退款？',
				item: {
					name:"",
					idNumber:"",
					gender:"",
					birthday:"",
					phone1:"",
					nation:"",
					address:"",
				},



			}
		},
		onLoad(option) {

			this.healthCode = this.GetParam(window.location.href, "healthCode");
			this.get()
			this.getmoren()
		
		},
		onShow() {
			//this.totijian();
		},
		computed: {
			...mapState(['token'], ['userInfo']),
			...mapGetters(['hasLogin', 'getUserInfo'])
		},
		methods: {
			GetParam(url, code) {
				url = url + "";
				let regstr = "/(\\?|\\&)" + code + "=([^\\&]+)/";
				let reg = eval(regstr);
				//eval可以将 regstr字符串转换为 正则表达式
				let result = url.match(reg);
				if (result && result[2]) {
					return result[2];
				}
			},
			get() {
				this.$request("HealthCard", "GetPerson", {
					healthCode: this.healthCode
				}).then(res => {
					console.error(res)
					this.item = res.data.rsp.card
					console.error(this.item)
					if (res.data.commonOut.resultCode == 0) {
						this.item = res.rsp.card

					} else {
						uni.showToast({
							title: "获取失败",
							icon: 'none',
							duration: 2000
						});

					}
				})



			},


				getmoren()
				{
					let pat
					this.$request('patient', 'defaultInfo', {		
					}).then(res => {
						console.log(res.data)
						if (res.code == 1) {
							// uni.showToast({
							// 	title: "成功获取PD",
							// 	icon: 'none',
							// 	duration: 2000
							// });
							pat= res.data.PatientId
							
							this.$request('patient', 'delete', {
								PatientId:pat
							}).then(res => {
								console.log(res.msg)
								if (res.code == 1) {
									uni.hideLoading();
									// uni.showToast({
									// 	title: pat,
									// 	icon: 'none',
									// 	duration: 2000
									// });
								} else {
									uni.hideLoading();
									// uni.showToast({
									// 	title: "失败",
									// 	icon: 'none',
									// 	duration: 2000
									// });
								}
							})
							
						} else {
							// uni.showToast({
							// 	title: "获取PD失败",
							// 	icon: 'none',
							// 	duration: 2000
							// });
							return 
						}
					})
					
					
					
					
					
				},

			// shanchu()
			// {
				 
			// 	uni.showLoading({
			// 		title: '提交中'
			// 	})	
			// 	this.$request('patient', 'submit', {
			// 		Name: "宋家兴",
			// 		Sex: "男",
			// 		IDCard: "320323199912012239",
			// 		Mobile: "19529347002"
			// 	}).then(res => {
					
			// 		if (res.code == 1) {
			// 			let doctorinfor = false
			// 			uni.hideLoading();
			// 			uni.switchTab({
			// 				url: `/pages/index/index`,
							
			// 			})
			// 		} else {
			// 			uni.hideLoading();
			// 			uni.showToast({
			// 				title: res.msg,
			// 				icon: 'none',
			// 				duration: 2000
			// 			});
			// 		}
			// 	})
				
				
			// },

			addvisit() {
				
				
				
				uni.showLoading({
					title: '提交中'
				})	
				this.$request('patient', 'submit', {
					Name: this.item.name,
					Sex: this.item.gender,
					IDCard: this.item.idNumber,
					Mobile: this.item.phone1
				}).then(res => {
					
					if (res.code == 1) {
						let doctorinfor = false
						
						uni.hideLoading();
						// const pages = getCurrentPages();
						// uni.showToast({
						// 	title: pages[0].route,
						// 	icon: 'none',
						// 	duration: 2000
						// });
						let Url=uni.getStorageSync('URL')
						if(Url!=null&&Url!="")
						{
							uni.clearStorage();
							uni.navigateTo({
								url: Url,
								
							})
							 
							
						}else{
						uni.switchTab({
							url: `/pages/index/index`,
							
						})
						}
					} else {
						uni.hideLoading();
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
					}
				})

			},

			getDetail() {
				uni.showLoading({
					title: '请稍后'
				})
				this.$request("Order", "Detail", {
					OrderId: this.OrderId
				}).then(res => {
					console.log("详情", res)
					if (res.code == 1) {
						this.item = res.data
						uni.hideLoading();

					} else {
						uni.hideLoading();
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
					}
				})
			},
			splitetext(text) {
				console.log(text)
				let temp = text + ''
				temp = Number.parseInt((temp.split("T")[0].split('-')[1])) + "月" + temp.split("T")[0].split('-')[2] + "日"
				return temp


			},
			
		
			cancellation() {
				console.log("进了")
				this.$request("RegTJRecord", "DelOrder", {
					TJRegisterId: this.item.TJRegisterId
				}).then(res => {
					console.log("res", res)
					if (res.code == 1) {

						this.cancellationComfirm = "取消成功"
						this.cancellationComfirmshow = true

					} else {
						this.cancellationComfirm = "取消失败"
						this.cancellationComfirmshow = true
					}
				})
			},
		
			toCancell() {

				uni.redirectTo({
					url: `/pages/MedicalExamination/Record/Record?current=${0}`,
					fail(error) {
						console.log(error)
					}
				})
				this.cancellationComfirmshow = false
			}
		}
	}
</script>

<style>
	@import './Healthcard.css'
</style>